<table id="users" class="admingrid">
</table>
<div id="users_pager"></div>

<script>
grids.users = {
    url : generateServiceUrl({
        admin : true,
        service : "getuserlist",
        page : "confirm"
    }),
    colNames : [
        "Username",
        "Real name",
        "Email",
        "Admin?",
        "Active?",
        "Registered at"
    ],
    colModel : [
        { name : "username",   index : "username",   width : 150 },
        { name : "realname",   index : "realname",   width : 200 },
        { name : "email",      index : "email",      width : 200 },
        { name : "admin",      index : "admin",      width : 50, formatter : booleanFormatter },
        { name : "active",     index : "active",     width : 50, formatter : booleanFormatter },
        { name : "registered", index : "registered", width : 100 }
    ],
    caption : "User list"
};

function users_clicked(item, rowid, presentvalue) {
    if (item.className == "admin") {
        var yn = confirm("Are you sure to want to " + (presentvalue ? "remove" : "add") + " admin status?");
        if (yn) {
            callAdminService("confirm", "toggleadmin", {
                userid : rowid,
                operation : (presentvalue ? "remove" : "add")
            }, {
                success : function() {
                    refreshGrid("users");
                }
            });
        }
    } else if (item.className == "active") {
        var yn = confirm("Are you sure to want to " + (presentvalue ? "deactivate" : "activate") + " user?");
        if (yn) {
            callAdminService("confirm", "toggleactive", {
                userid : rowid,
                operation : (presentvalue ? "deactivate" : "activate")
            }, {
                success : function() {
                    refreshGrid("users");
                }
            });
        }
    }
}

</script>

